#!/bin/bash
for node_name in {{master_name}}
  do
    # 创建 token
    export BOOTSTRAP_TOKEN=$(/usr/local/bin/kubeadm token create --description kubelet-bootstrap-token --groups system:bootstrappers:${node_name} --kubeconfig ~/.kube/config)
    # 设置集群参数
    /usr/local/bin/kubectl config set-cluster kubernetes --certificate-authority=/etc/kubernetes/ssl/ca.pem --embed-certs=true --server=https://{{keepalived_vip}}:8443 --kubeconfig=kubelet-bootstrap-${node_name}.kubeconfig
    # 设置客户端认证参数
    /usr/local/bin/kubectl config set-credentials kubelet-bootstrap --token=${BOOTSTRAP_TOKEN} --kubeconfig=kubelet-bootstrap-${node_name}.kubeconfig
    # 设置上下文参数
    /usr/local/bin/kubectl config set-context default --cluster=kubernetes --user=kubelet-bootstrap --kubeconfig=kubelet-bootstrap-${node_name}.kubeconfig
    # 设置默认上下文
    /usr/local/bin/kubectl config use-context default --kubeconfig=kubelet-bootstrap-${node_name}.kubeconfig
  done
